﻿using nplJobsCommon.Employeer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Delete
{
    //public class DeleteContactPerson : DataAccessBase
    //{
    //    public DeleteContactPerson()
    //    {
    //        StoredProcedureName = StoredProcedure.Name.spDeleteEmployeerContactPerson.ToString();
    //    }
    

    //    public void invoke()
    //    {
    //        DataBaseHelper _db = new DataBaseHelper(StoredProcedureName);

    //        try
    //        {
    //            SqlParameter[] _params = { 
    //                                        new SqlParameter("@EmployeerID",     this.EmployeerID),
    //                                        new SqlParameter("@ContactPersonID",     this.ContactPersonID),
    //                                     };

    //            _db.Run(base.ConnectionString, _params);
    //        }
    //        catch (Exception ex)
    //        {
    //            throw ex;
    //        }

    //        finally
    //        {
    //            _db = null;
    //        }
    //    }
    //}

    public class DeleteContactPerson : DataAccessBase
    {
        public EmployeerContactPerson EmployeerContactPerson;

        public int isDeleted;

        public DeleteContactPerson()
        {
            StoredProcedureName = StoredProcedure.Name.spDeleteEmployeerContactPerson.ToString();
        }

        public void invoke()
        {
            DeleteContactPersonDataParameters contactUpdateDataParameters = new DeleteContactPersonDataParameters(this.EmployeerContactPerson);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = contactUpdateDataParameters.Parameters;
            dbHelper.RunScalar();

            if (contactUpdateDataParameters.Parameters[2].Value != null)
            {
                isDeleted = int.Parse(contactUpdateDataParameters.Parameters[2].Value.ToString());
            }
        }
    }

    #region SQL Parameters for  Delete Contact Person Insert Data
    public class DeleteContactPersonDataParameters
    {
        private EmployeerContactPerson EmployeerContactPerson;
        int isDeleted = 0;

        public DeleteContactPersonDataParameters(EmployeerContactPerson employeerContactPerson)
        {
            this.EmployeerContactPerson = employeerContactPerson;
            Build();
        }

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@EmployeerID", EmployeerContactPerson.EmployeerID),
                    new SqlParameter("@ContactPersonID", EmployeerContactPerson.ContactPersonID),
                    new SqlParameter("@DeleteUnique",isDeleted){ Direction =System.Data.ParameterDirection.Output}
                };

            Parameters = parameters;
        }

        public SqlParameter[] Parameters { get; set; }
    }
    #endregion
}
